登录 白背景

leetcode/100-n/461. 汉明距离.md

https://leetcode-cn.com/problems/hamming-distance/
几乎复制了大佬的代码

class Solution {
public:
    int hammingDistance(int x, int y) {
        int ret = 0;
        //xor求不同的位置
        int xorNum = x ^ y;
        while(xorNum > 0){
            //使用-1再&的方法,快速筛选所有1的位置,可以快速遍历完成
            xorNum = xorNum & (xorNum - 1);
            ret++;
        }
        return ret;
    }
};